# -*- conding:utf-8 -*-
import re
import traceback

import execjs
import requests
from lxml import html
from urllib import parse
import time

"""
@author:ym
@time:09-2019/9/2
在别的地方登陆，表示你Cookie根本没有完全认证成功
该文件，只包括了，基本的登录、抢课、自动评教
2020-06-25-21：03 对代码检查，能正常运行
"""


class Logger:
    """
    日志类
    """

    def __init__(self):
        self.file = "logger.log"
        try:
            with open(self.file, "r", encoding="UTF-8") as f:
                f.close()
        except:
            with open(self.file, "w+", encoding="UTF-8") as f:
                f.close()

    def write(self, mes):
        with open(self.file, "a+", encoding="UTF-8") as f:
            mes = str(self.__get_time()) + "：" + str(mes)
            f.writelines(mes)
            # 测试使用
            print(mes)

    def __get_time(self):
        return time.strftime('%m-%d-%H:%M:%S ', time.localtime(time.time()))


class School:
    """
    __init__: usre  password  登录使用的账号密码
    get_js ： 调用js来加密得到信息
    login_in： 登录，成功返回true
    """

    def __init__(self, user, password):
        self.ses = requests.session()
        self.logger = Logger()
        self.user = user
        self.password = password
        self.cookies = ""
        self.header = {}
        self.doMain = "jwgl.hutb.edu.cn"

    def __get_js(self, msg):  # python 调用JS加密 返回 加密后的结果
        with open('conwork.js', encoding='utf-8') as f:
            js = execjs.compile(f.read())
            return js.call('encodeInp', msg)

    def __get_login_cookies(self):
        """
        首次登陆获得Cookies
        :return:
        """

        header = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0",
            "Upgrade-Insecure-Requests": "1",
            "Connection": "keep-alive",
            "Host": "jwgl.hutb.edu.cn"
        }
        self.header = header
        url = "http://jwgl.hutb.edu.cn/jsxsd/"
        try:
            stat = self.ses.get(url=url, headers=header, timeout=1000).status_code
            if stat != 200:
                mes = "教务系统进入失败！:School->81"
                # print(mes)
                return None
            # self.ses.cookies = stat.
            cookies = self.ses.cookies.get_dict()  # 获得临时的cookies
            cookies = str(cookies).replace("{", '').replace("'", '').replace(":", '=').replace('}', '').replace(",",
                                                                                                                ";")
            cookies = cookies.replace("= ", "=")
            self.cookies = cookies
            return cookies

        except:
            mes = "教务系统进入抛出错误！:School->87"
            # print(mes)
            return None

    def __login(self, jsmsg):
        """
        登陆，让Cookie通过验证
        :param jsmsg: 账号密码加密过的东西
        :return:
        """
        header = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Encoding": "gzip, deflate",
            "Connection": "keep-alive",
            "Content-Type": "application/x-www-form-urlencoded",  # 接收类型
            "Host": "jwgl.hutb.edu.cn",
            "Referer": "http://jwgl.hutb.edu.cn/jsxsd/",
            "Upgrade-Insecure-Requests": "1",
            "Origin": "http://jwgl.hutb.edu.cn",
            "Proxy-Connection": "keep-alive",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0",
        }
        PostData = {
            'encoded': jsmsg  # 账号密码加密后的东西
        }
        url = 'http://jwgl.hutb.edu.cn/jsxsd/xk/LoginToXk'
        try:
            # 让Cookies 通过验证
            msg = self.ses.post(url, headers=header, data=PostData, timeout=3000)
            # print(msg.)
            if (msg.status_code != 200):
                msg = "登录页面失败！School->84"
                print(msg)
                return False
            tree = html.fromstring(msg.text)
            # 查看是否有提示密码错误
            error = tree.xpath("//font[@color='red']/text()")
            if len(error) > 0:
                if str(error[0]) == "用户名或密码错误":
                    msg = "用户名或密码错误!"
                    print(msg)
                    return False
            return True
        except Exception as e:
            msg = "登录抛出异常!"
            return False

    def login_in(self):
        """
        外部调用登陆
        :return:
        """
        jsmsg = str(self.__get_js(self.user)) + "%%%" + str(self.__get_js(self.password)) + "="
        if self.__get_login_cookies():  # cookies 初始化
            if self.__login(jsmsg):
                return True
            else:
                return False
        else:
            return False

    def __get_qk_page1(self):

        url = "http://jwgl.hutb.edu.cn/jsxsd/xsxk/xklc_list"
        response = self.ses.get(url=url)
        if response.status_code != 200:
            return False
        url = re.findall("<a href=\".*\">进入选课</a>", response.text)
        if len(url) < 1:
            return False
        url = str(url[1]).replace("<a href=\"/", "").replace("\">进入选课</a>", "").replace(
            "jsxsd/xsxk/xklc_view?jx0502zbid=", "")
        return url

    def verification(self):
        """
        检验用户，并获取用户名
        :return: 返回用户名
        """
        # 验证是否正常成功
        url = "http://jwgl.hutb.edu.cn/jsxsd/framework/xsMain.jsp"
        response = self.ses.get(url=url).text
        # 姓名和学号的 xpath： /html/body/div[5]/div/div[3]
        tree = html.fromstring(response)
        user = tree.xpath("/html/body/div[5]/div/div[3]/text()")
        userId = str(user[0]).replace("\n", "").replace("\t", "").replace("姓名：", "").replace(" ", "")
        return userId

    def is_ready(self):
        """
        教务系统是抢课是否能正常进入
        :return: bool 类型
        """
        url = "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc"
        try:
            response = self.ses.get(url=url, timeout=5).text
            mes = re.findall(r"<title>.*</title>", response)[0]
            if str(mes) == "<title>错误提示页面</title>":
                self.logger.write("抢课目前正在维护")
                return False
            else:
                return True
        except:
            pass

    def get_qk_page(self):
        zbid = self.__get_qk_page1()
        if not zbid:
            self.logger.write("抢课系统未开放")
            return False
        if self.__get_qk_page2(zbid=zbid):
            return True
        else:
            return False

    def __get_qk_page2(self, zbid):
        "/jsxsd/xsxk/xsxk_index?jx0502zbid="
        url = "http://jwgl.hutb.edu.cn/jsxsd/xsxk/xsxk_index?jx0502zbid=" + str(zbid)
        headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "max-age=0",
            "Cookie": self.cookies,
            "Host": "jwgl.hutb.edu.cn",
            "Proxy-Connection": "keep-alive",
            "Referer": "http://jwgl.hutb.edu.cn/jsxsd/xsxk/xklc_view?jx0502zbid=0B78EA08934C47148576964D6A532F4D",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0",
        }
        try:
            response = self.ses.get(url=url, headers=headers)
            if response.status_code != 200:
                self.logger.write("School->181:抢课进入失败!")
                return False
            return True
        except Exception as e:
            return False

    def findClassByOne(self, kcName, kcTeacher, kcWeek, kcJC):
        """
        查找唯一的课程
        :param kcName: 课程名字
        :param kcTeacher: 老师
        :param kcWeek: 上课星期
        :param kcJC: 上课节次
        :return: 课程唯一ID，或者None{"code": 200, "msg": "添加成功！", "jxid": str(jxid),"type":1}
              最后一个表示是那种类型的课程
        注意URL的汉字需要转urlencode,要转两次，
        """
        # 转码
        kcTeacher = parse.quote(parse.quote(str(kcTeacher)))
        kcName = parse.quote(parse.quote(str(kcName)))
        jxid = ""
        url1 = "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=" + str(
            kcName) + "&skls=" + str(kcTeacher) + "&skxq=" + str(kcWeek) + "&skjc=" + str(
            kcJC) + "&sfym=false&sfct=true&szjylb=&sfxx=true"
        # 必修URL
        url2 = "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc/xsxkBxxk?kcxx=" + str(
            kcName) + "&skls=" + str(kcTeacher) + "&skxq=" + str(kcWeek) + "&skjc=" + str(
            kcJC) + "&sfym=false&sfct=true&szjylb=&sfxx=true"
        data = {
            "sEcho": "1",
            "iColumns": "16",
            "sColumns": "",
            "iDisplayStart": "0",
            "iDisplayLength": "15",
            "mDataProp_0": "kch",
            "mDataProp_1": "kcmc",
            "mDataProp_2": "kcsx",
            "mDataProp_3": "zxs",
            "mDataProp_4": "ktmc",
            "mDataProp_5": "xxrs",
            "mDataProp_6": "syrs",
            "mDataProp_7": "xf",
            "mDataProp_8": "skls",
            "mDataProp_9": "sksj",
            "mDataProp_10": "skdd",
            "mDataProp_11": "xqmc",
            "mDataProp_12": "xkrs",
            "mDataProp_13": "ctsm",
            "mDataProp_14": "szkcflmc",
            "mDataProp_15": "czOper"
        }
        data2 = {
            "sEcho": "1",
            "iColumns": "15",
            "sColumns": "",
            "iDisplayStart": "0",
            "iDisplayLength": "15",
            "mDataProp_0": "kch",
            "mDataProp_1": "kcmc",
            "mDataProp_2": "kcsx",
            "mDataProp_3": "zxs",
            "mDataProp_4": "ktmc",
            "mDataProp_5": "xxrs",
            "mDataProp_6": "syrl",
            "mDataProp_7": "xf",
            "mDataProp_8": "skls",
            "mDataProp_9": "sksj",
            "mDataProp_10": "skdd",
            "mDataProp_11": "xqmc",
            "mDataProp_12": "xkrs",
            "mDataProp_13": "ctsm",
            "mDataProp_14": "czOper"
        }
        head1 = {
            "Host": "jwgl.hutb.edu.cn",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0",
            "Accept": "*/*",
            "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "Accept-Encoding": "gzip, deflate",
            # "Referer": "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc/comeInGgxxkxk",
            "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
            "X-Requested-With": "XMLHttpRequest",
            "Connection": "keep-alive",
            "Cookie": self.cookies,
            "Pragma": "no-cache",
            "Cache-Control": "no-cache",
        }
        try:
            response = requests.post(url=url1, data=data, headers=head1)
            if response.status_code != 200:
                self.logger.write("请求异常")
                return None
            msg = response.json()
            try:
                # 如何没有抛出异常那就有问题
                # print(msg)
                if str(msg["flag1"]) == str(2):
                    self.logger.write("请先登录系统")
                    return False
            except:
                pass
            try:
                # print(msg)
                addData = msg["aaData"]
                # 如果是空的，直接返回
                if not addData:
                    # 查询必修课课
                    response = requests.post(url=url2, data=data2, headers=head1)
                    if response.status_code != 200:
                        self.logger.write("请求异常")
                        return None
                    msg = response.json()
                    try:
                        # 如何没有抛出异常那就有问题
                        # print(msg)
                        if str(msg["flag1"]) == str(2):
                            self.logger.write("请先登录系统")
                            return False
                    except:
                        pass
                    try:
                        addData = msg["aaData"]
                        if not addData:  # 如果是空的，返回
                            return {"code": 100, "msg": "找不到该课程请检查课程和老师以及上课时间！"}
                        for i in addData:
                            print(i)
                            jxid = i["jx0404id"]
                        if jxid:
                            return {"code": 200, "msg": "添加成功！", "jxid": str(jxid), "type": 2}
                    except:
                        self.logger.write(str(traceback.format_exc()))

                for i in addData:
                    # self.logger.write(i)
                    jxid = i["jx0404id"]
                if jxid:
                    return {"code": 200, "msg": "添加成功！", "jxid": str(jxid), "type": 1}
            except:
                self.logger.write(str(traceback.format_exc()))
                return None
        except:
            self.logger.write("error By findClassByOne")
            return None
        """
        {"flag1":2,"msgContent":"请先登录系统"}

        """

    def post_Class(self, id):
        """
        提交必修抢课
        :param id:
        :return:
        """
        # 必修抢课
        url = "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc/bxxkOper?jx0404id=" + str(id)
        # 公共课抢课
        # url = "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc/ggxxkxkOper?jx0404id=201920202004162&xkzy=&trjf="
        # url = "http://jwgl.hutb.edu.cn/jsxsd/xsxkkc/ggxxkxkOper?jx0404id=" + str(id) + "&xkzy=&trjf="
        header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0",
            'Referer': 'http://172.30.1.70/srun_portal_pc.php?ac_id=1',
        }

        try:
            response = self.ses.get(url=url)
            self.logger.write(str(id) + ":" + str(response.status_code))
            if response.status_code != 200:
                print("出现异常")
                return False
            msg = response.json()
            self.logger.write(msg)
        except:
            pass
            # print()
        """
        #  Cookie 唯一，最好不要在多个地方登录
        返回的类型：
        下面两个状态需要发挥异常，重新登录
        404
        请登录
        {"flag1":2,"msgContent":"请先登录系统"}
        选课失败
        {"success":false,"message":"选课失败：当前课程往年已选择！"}
        # 选课失败
        {"success":false,"message":"选课失败：此课堂选课人数已满！"}
        
        # 选课失败，
        {"success":false,"message":"选课失败：系统设定了当前全校公共选修课选课学分不能超过2学分！"}
        
        # 选课成功
        {"jfViewStr":"","success":true}
        # 选课失败，当前已经选则，就是抢课成功
        {"success":false,"message":"选课失败：当前教学班已选择！"}
        """

    def commentTeaching(self):
        """
        自动评教功能，
        如果出现任何异常直接退出
        :return: 无返回
        """
        try:
            url = "http://jwgl.hutb.edu.cn/jsxsd/framework/xsMain.jsp"
            response = self.ses.get(url=url)
            text = response.text
            newUrl = re.findall(r"<a href=\"/jsxsd/xspj/xspj_find.do.*?\">", response.text)
            if newUrl.__len__() == 0:
                raise Exception("进入主页面失败")
            newUrl = str(newUrl[0]).replace("<a href=\"", "").replace("\">", "")
            newUrl = "http://" + self.doMain + newUrl
            response = self.ses.get(url=newUrl, timeout=3000)
            if not self.checkRequest(response, "评教列表"):
                return
            text = response.text
            comments = re.findall(r"<a href=\"/jsxsd/xspj/xspj_list.do\?.*?\" title=\"点击进入评价\">进入评价</a>", text)
            self.logger.write("可评教数：" + str(comments.__len__()) + "个")
            if comments.__len__() <= 0:
                self.logger.write("暂无评教....")
                return
            count = 0
            for i in comments:
                i = str(i).replace("<a href=\"", "").replace("\" title=\"点击进入评价\">进入评价</a>", "")
                i = "http://" + self.doMain + i
                self.__goToComment(i, count)
                count += 1
                # return
        except Exception as e:
            self.logger.write(e)

    def __goToComment(self, url, count):
        """
        根据大类自动评教
        :param url: 大类的URL
        :param count: 目前是第几个大类
        :return:
        """

        response = self.ses.get(url=url, timeout=3000)
        if not self.checkRequest(response, "评教页面"):
            return
        curriculums = re.findall(r"<a href=\"javascript:openWindow\(\'/jsxsd/xspj/xspj_edit.do\?.*?\">..</a>",
                                 response.text)
        if curriculums.__len__() == 0:
            return
        for i in curriculums:
            i = str(i).replace("<a href=\"javascript:openWindow(\'", "").split("\'")[0]
            i = "http://" + self.doMain + i
            self.__postCpmments(i, count)

    def __postCpmments(self, url, i):
        """
        对单个课程评教
        :param url: 当个课程所在的url
        :param i:  使用哪个数据提交，0表示理论课 1是实验课，
                    可以共用，能显示分数，但是自己单独进入不会出现你的选项
        :return:
        """

        response = self.ses.get(url=url, timeout=3000)
        if not self.checkRequest(response, "提交评教"):
            return
        pj09id = re.findall(r"<input type=\"hidden\" name=\"pj09id\" value=\".*?\" />", response.text)[0]
        pj09id = str(pj09id).replace("<input type=\"hidden\" name=\"pj09id\" value=\"", "").replace("\" />", "")
        pj01id = re.findall(r"<input type=\"hidden\" name=\"pj01id\" value=\".*?\" />", response.text)[0]
        pj01id = str(pj01id).replace("<input type=\"hidden\" name=\"pj01id\" value=\"", "").replace("\" />", "")
        pj0502id = re.findall(r"<input type=\"hidden\" name=\"pj0502id\" value=\".*?\" />", response.text)[0]
        pj0502id = str(pj0502id).replace("<input type=\"hidden\" name=\"pj0502id\" value=\"", "").replace("\" />", "")
        jg0101id = re.findall(r"<input type=\"hidden\" name=\"jg0101id\" value=\".*?\" />", response.text)[0]
        jg0101id = str(jg0101id).replace("<input type=\"hidden\" name=\"jg0101id\" value=\"", "").replace("\" />", "")
        jx0404id = re.findall(r"<input type=\"hidden\" name=\"jx0404id\" value=\".*?\" />", response.text)[0]
        jx0404id = str(jx0404id).replace("<input type=\"hidden\" name=\"jx0404id\" value=\"", "").replace("\" />", "")
        xsflid = re.findall(r"<input type=\"hidden\" name=\"xsflid\" value=\".*?\" />", response.text)[0]
        xsflid = str(jg0101id).replace("<input type=\"hidden\" name=\"xsflid\" value=\"", "").replace("\" />", "")
        xnxq01id = re.findall(r"<input type=\"hidden\" name=\"xnxq01id\" value=\".*?\" />", response.text)[0]
        xnxq01id = str(xnxq01id).replace("<input type=\"hidden\" name=\"xnxq01id\" value=\"", "").replace("\" />", "")
        jx02id = re.findall(r"<input type=\"hidden\" name=\"jx02id\" value=\".*?\" />", response.text)[0]
        jx02id = str(jx02id).replace("<input type=\"hidden\" name=\"jx02id\" value=\"", "").replace("\" />", "")
        pj02id = re.findall(r"<input type=\"hidden\" name=\"pj02id\" value=\".*?\" />", response.text)[0]
        pj02id = str(pj02id).replace("<input type=\"hidden\" name=\"pj02id\" value=\"", "").replace("\" />", "")
        name = re.findall(r"课程名称：.*?评教大类", response.text)[0]
        name = str(name).replace("课程名称：", "").replace("&nbsp;", "").replace("评教大类", "")
        if int(i) == 0:
            data = [
                ("issubmit", "1"),
                ("pj09id", pj09id),
                ("pj01id", pj01id),
                ("pj0502id", pj0502id),
                ("jg0101id", jg0101id),
                ("jx0404id", jx0404id),
                ("xsflid", xsflid),
                ("xnxq01id", xnxq01id),
                ("jx02id", jx02id),
                ("pj02id", pj02id),
                ("pj06xh", "11"),
                ("pj0601id_11", "1F099C54AE5F4788890D0081BFAC5899"),
                # ("pj0601fz_11_5C08C497AAA743B2840F7F8DBCAA6E07", "2.5"), 后面代表的是分数，可以满分
                ("pj06xh", "7"),
                ("pj0601id_7", "D03BC1C6CF76495F9B7EC48416061805"),
                ("pj06xh", "12"),
                ("pj0601id_12", "A42D16FF6CE64F449C9B385CACBDAD47"),
                ("pj06xh", "1"),
                ("pj0601id_1", "A00E90F1D3F94A67AD4D4A49C1653EA2"),
                ("pj06xh", "9"),
                ("pj0601id_9", "70A54A3E2D934F26ABBCBF39C3AA1513"),
                ("pj06xh", "5"),
                ("pj0601id_5", "CD0E229349BF42D8BC1ACB4E7E3EE6C4"),
                ("pj06xh", "8"),
                ("pj0601id_8", "AC4C61F05FDE4EC9A581222086CE8E6D"),
                ("pj06xh", "3"),
                ("pj0601id_3", "FBF2B384081F4D4FBE2B3D1E481C2D37"),
                ("pj06xh", "4"),
                ("pj0601id_4", "41C5449E2F6A4A0585F248C348A48053"),
                ("pj06xh", "2"),
                ("pj0601id_2", "5EED2BFBE7E74083B3793A1B43289FC8"),
                ("pj06xh", "10"),
                ("pj0601id_10", "598C6B30064448719ADF94FC07E09DC7"),
                ("pj06xh", "6"),
                ("pj0601id_6", "F17D9CE0EF6B4EB0850EAC4CC2BE9B92"),
                ("pj03id", "991C969F747A44D09D81C1DBBED9ED9C"),
                ("jynr", "")]
        else:
            data = [
                ("issubmit", "1"),
                ("pj09id", pj09id),
                ("pj01id", pj01id),
                ("pj0502id", pj0502id),
                ("jg0101id", jg0101id),
                ("jx0404id", jx0404id),
                ("xsflid", xsflid),
                ("xnxq01id", xnxq01id),
                ("jx02id", jx02id),
                ("pj02id", pj02id),
                ("pj06xh", "12"),
                # AEBADA585DC049D9B904E714AD98F479   100分改这个就好了
                # 99.5 53DA7F8074E64CEDB7A938F2D7E2A5A3
                ("pj0601id_12", "53DA7F8074E64CEDB7A938F2D7E2A5A3"),  # 这一个扣0.5分哦，需要满分自动修改参数
                ("pj06xh", "8"),
                ("pj0601id_8", "68E4E54E764D4E68B1278386A4242846"),
                ("pj06xh", "12"),
                ("pj0601id_12", "A42D16FF6CE64F449C9B385CACBDAD47"),
                ("pj06xh", "9"),
                ("pj0601id_9", "4A23CE51B55040C3BDA10DA9ECD1F9F5"),
                ("pj06xh", "4"),
                ("pj0601id_4", "3ECDA30E2D774036B23FBBFE8052EAD5"),
                ("pj06xh", "10"),
                ("pj0601id_10", "7A0305B56842461E9A52FFE8897A90F4"),
                ("pj06xh", "6"),
                ("pj0601id_6", "349AD4AC8F194BEFA257AF5167000384"),
                ("pj06xh", "3"),
                ("pj0601id_3", "FAB333027A2846D19F16423DF430E5F8"),
                ("pj06xh", "7"),
                ("pj0601id_7", "76991321C528462483768AEEB3F78634"),
                ("pj06xh", "11"),
                ("pj0601id_11", "237D616FC4C54E08A151ECEF1FBFBA98"),
                ("pj06xh", "5"),
                ("pj0601id_5", "48DBC5876D7642D1947925F47A22430B"),
                ("pj06xh", "1"),
                ("pj0601id_1", "754EA107AC4D4B68B9A60A7EA101E436"),
                ("pj06xh", "2"),
                ("pj0601id_2", "435C5117AC5742A3A6D2B1ACCADED943"),
                ("pj03id", "991C969F747A44D09D81C1DBBED9ED9C"),
                ("jynr", "")]
        response = self.ses.post(url="http://jwgl.hutb.edu.cn/jsxsd/xspj/xspj_save.do", data=data, timeout=3000)
        if not self.checkRequest(response, "提交表单"):
            return
        self.logger.write("当前评教的课程是：" + name)
        if "保存成功" in response.text:
            print(response.text)

    def checkRequest(self, response, name):
        """
        检查请求是否正常
        :param response:
        :param name: 请求的名称
        :return: bool
        """
        try:
            if response.status_code != 200:
                self.logger.write(name + "：请求异常")
                return False
            return True
        except Exception as e:
            return False


if __name__ == '__main__':
    a = School(user="你的学号", password="你的密码")
    a.login_in()  # 模拟登录
    # a.get_qk_page()
    a.commentTeaching()  # 自动评教
